{extend name="layout:base" /}{block name="content"}

<?php
$global=isSupperManagerForSession();
?>
<link rel="stylesheet" type="text/css" href="/static/My97DatePicker/skin/WdatePicker.css" />
<script charset="utf-8" src="/static/My97DatePicker/WdatePicker.js"></script>
<style type="text/css">
    .yg_inp>input{margin-bottom: 10px;}
    #zc_detail table{margin:10px;}
    #zc_detail table tr td{border: 1px solid #ddd;height:40px;line-height:40px;padding-left:5px;padding-right:5px;}
    .ordertable input {width:90%;}
    .policeLable{padding:2px 4px;margin-left:4px;}
    #taskDate .taskDateItem{width:100%;height:40px;line-height:40px;margin:4px 0px;}
    #taskDate .taskDateItem .taskDateItemLeft{width:10%;float:left;}
    #taskDate .taskDateItem .taskDateItemRight1{width:70%;float:left;border:1px solid #139667;height: 42px;}
    #taskDate .taskDateItem .taskDateItemRight2{width:20%;float:right;}
    #taskDate .taskDateItem .opUsers img{width:22px;margin-left:5px;}
    #taskDate .taskDateItem .itemUser{padding: 4px 6px;background:#139667;margin-left:4px;color:white;}
    #taskDate .taskDateItem .clear{clear:both;width:0px;height:0px;overflow:hidden;}
    #taskDate .taskDateItem .jia,#taskDate .taskDateItem .jian{font-size:30px;cursor:pointer;font-weight:800;margin-left:5px;}
</style>

<!--引入JS-->
<script type="text/javascript" src="/static/admin/js/ajaxfileupload.js?t=1"></script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/lang/zh-cn/zh-cn.js"></script>

<section class="topBanners">
         <div class="icon"></div>
         <div class="topBannersNav">
        <span data-url="/admin/classlist/lists" onclick="ContentLoadGo('/admin/classlist/lists')">挑战管理</span>
         >
         <span data-url="/admin/classlist/addData"  onclick="ContentLoadGo('/admin/classlist/addData')"  >添加</span>
         </div>
</section>
<section id="zc_detail">
<table class="ordertable" style="width:100%;" border="0" cellspacing="0" cellpadding="0">
     <tr>
       <td width="120"><div align="right">挑战名称</div></td>
       <td class="tr_cons">
       <input type="text" name="data[classname]" id="classname" value="<?php echo $info['classname']; ?>" placeholder="" class="textbox" style="padding:0px;" />
       </td>
     </tr>

      <tr>
       <td width="120"><div align="right">当前期数</div></td>
       <td class="tr_cons">
       <input type="text" name="data[classnumber]" id="classnumber" value="<?php echo $info['classnumber']; ?>" placeholder="" class="textbox" style="padding:0px;" />
       </td>
     </tr>
     
     <tr>
       <td width="120"><div align="right">本期天数</div></td>
       <td class="tr_cons">
       <input type="text" name='data[days]' id='days' style="width:100px;" value="<?php echo $info['days']; ?>" placeholder="" class="textbox" style="padding:0px;" />
       <font style="font-size:12;color:red">提示：课程天数为[1-100]的整数</font>
       </td>
     </tr>


    <tr>
        <td width="120"><div align="right">报名日期</div></td>
        <td class="tr_cons">
            <input name="data[bm_starttime]"  id="bm_starttime" class="Wdate textbox" placeholder="开始日期"
                   onfocus="WdatePicker({lang:'zh-cn',dateFmt: 'yyyy-MM-dd'})" value="" size="12"  type="text" style="padding: 0 5px;font-size: 12px;border: 1px #139667 solid;vertical-align: middle;width:150px;" >
            至
            <input name="data[bm_endtime]"  id="bm_endtime" class="Wdate textbox" placeholder="结束日期"
                   onfocus="WdatePicker({lang:'zh-cn',dateFmt: 'yyyy-MM-dd'})" value="" size="12"  type="text" style="padding: 0 5px;font-size: 12px;border: 1px #139667 solid;vertical-align: middle;width:150px;" >
        </td>
    </tr>

    <tr>
        <td width="120"><div align="right">打卡开始日期</div></td>
        <td class="tr_cons">
            <input name="data[task_time]"  id="task_time" class="Wdate textbox" placeholder="开始日期"
                   onfocus="WdatePicker({lang:'zh-cn',dateFmt: 'yyyy-MM-dd'})" value="" size="12"  type="text" style="padding: 0 5px;font-size: 12px;border: 1px #139667 solid;vertical-align: middle;width:150px;" >
        </td>
    </tr>
    <tr>
        <td width="120"><div align="right">打卡时段</div></td>
        <td class="tr_cons">
           <select name="data[click_start]" id="click_start" class="select">
                <?php
                for($i=0;$i<24;$i++)
                {
                    $str1 = $i<10?'0'.$i:$i;
                    $str2 = $str1.":".'00';
                    $str3 = $str1.":".'30';
                ?>
                <option value="<?php echo $str2 ?>"><?php echo $str2; ?></option>
                <option value="<?php echo $str3 ?>"><?php echo $str3; ?></option>
                <?php
                }
                ?>
            </select>-
            <select name="data[click_end]" id="click_end" class="select">
                <?php
                for($i=0;$i<24;$i++)
                {
                    $str1 = $i<10?'0'.$i:$i;
                    $str2 = $str1.":".'00';
                    $str3 = $str1.":".'30';
                ?>
                <option value="<?php echo $str2 ?>"><?php echo $str2; ?></option>
                <option value="<?php echo $str3 ?>"><?php echo $str3; ?></option>
                <?php
                }
                ?>
            </select>
        </td>
    </tr>

    <tr>
        <td width="120"><div align="right">开奖日期</div></td>
        <td class="tr_cons">
            <input name="data[reward_date]"  id="reward_date" class="Wdate textbox" placeholder="开奖日期"
                   onfocus="WdatePicker({lang:'zh-cn',dateFmt: 'yyyy-MM-dd'})" value="" size="12"  type="text" style="padding: 0 5px;font-size: 12px;border: 1px #139667 solid;vertical-align: middle;width:150px;" >
            <select name="data[reward_time]" id="reward_time" class="select">
                <?php
                for($i=0;$i<24;$i++)
                {
                    $str1 = $i<10?'0'.$i:$i;
                    $str2 = $str1.":".'00';
                    $str3 = $str1.":".'30';
                ?>
                <option value="<?php echo $str2 ?>"><?php echo $str2; ?></option>
                <option value="<?php echo $str3 ?>"><?php echo $str3; ?></option>
                <?php
                }
                ?>
            </select>
        </td>
    </tr>


    <tr>
        <td width="120"><div align="right">开奖设置</div></td>
        <td class="tr_cons">
            <select name="data[is_auto_open_reward]" id="is_auto_open_reward" class="select">
                <option value="0">到点自动开奖</option>
                <option value="1">手动开奖</option>
            </select></td>
    </tr>

    <tr>
       <td width="120"><div align="right">挑战金额</div></td>
       <td class="tr_cons">
       <input type="text" name='data[money]' id='money' value="<?php echo $info['money']; ?>" placeholder="" class="textbox" style="padding:0px;" />元/人
       </td>
     </tr>

    <tr>
        <td width="120"><div align="right">每份额外奖励</div></td>
        <td class="tr_cons">
            <input type="text" name='data[reward_money]' id='reward_money' value="<?php echo $info['reward_money']; ?>" placeholder="" class="textbox" style="padding:0px;" />元/人
        </td>
    </tr>

    <tr>
        <td width="120"><div align="right">最大购买数量</div></td>
        <td class="tr_cons">
            <input type="text" name='data[max]' id='max' value="1" placeholder="" class="textbox" style="padding:0px;width:100px;" />份/人
            <font style="font-size:12;color:red">提示：最大购买数量为[1-100]的整数</font>
        </td>
    </tr>
     
     <tr>
       <td width="120"><div align="right">是否推荐</div></td>
       <td class="tr_cons">
       <select name="data[hot]" id="hot" class="select">
      		<option value="0">普通</option>
		    <option value="1">推荐</option>
      		</select></td>
     </tr>
     
      <tr>
       <td width="120"><div align="right">是否上架</div></td>
       <td class="tr_cons">
       <select name="data[stats]" id="stats" class="select">
      		<option value="0">上架</option>
		    <option value="1">下架</option>
      		</select></td>
     </tr>
     
      <tr>
         <td><div align="right">封面图</div></td>
         <td>
            <form id="jvForm" name="jvForm" action="/api/face/updateImage1" method="post" enctype="multipart/form-data">
            <input type="hidden" name="data[img]" id="uImage" value="<?php echo $info['img'] ?>" />
              <a style="position:relative;display:block;width:100px;height:30px;background:#EEE;border:1px solid #999;text-align:center;line-height:30px;"  href="javascript:void(0);" >上传文件
                <input style="position:absolute;left:0;top:0;width:100px;height:30px;z-index:999;opacity:0;" onchange="uploadPic()" type="file" name="file" id="fileImage"  />
                </a>
           
            <div id="updateimg"></div>
              </form>
         </td>
      </tr>
     
     <tr>
         <td><div align="right">视频</div></td>
         <td>
            <form id="jvFormV" name="jvFormV" action="/api/face/updateImage1" method="post" enctype="multipart/form-data">
            <input type="hidden" name="data[video]" id="uVideo" value="<?php echo $info['video']; ?>" />
              <a style="position:relative;display:block;width:100px;height:30px;background:#EEE;border:1px solid #999;text-align:center;line-height:30px;"  href="javascript:void(0);" >视频文件
                <input style="position:absolute;left:0;top:0;width:100px;height:30px;z-index:999;opacity:0;" onchange="uploadPicV()" type="file" name="file" id="fileVideo"  />
                </a>
           <div id="uploadProgress"></div>
            <div id="updateimgV"></div>
              </form>
         </td>
      </tr>

    <tr>
        <td><div align="right">规则</div></td>
        <td colspan="7">
            <script id="editor1" type="text/plain" style="width:96%;height:300px;"></script>
            </td>
     </tr>

      <tr>
         <td><div align="right">详情</div></td>
         <td colspan="7">
            <script id="editor" type="text/plain" style="width:96%;height:500px;"></script> 
         </td>
      </tr>

     <tr>
       <td style="height:50px;text-align:center;" colspan="2">
			<input type="button" power="70000"  style="width:80px;margin-top:4px;margin-bottom:4px;padding:0px;" value="添加" class="link_btn add"/>
       </td>
     </tr>
   </table>
</section>
<script type="text/javascript">
  UE.getEditor('editor').addListener("ready", function () {});
  UE.getEditor('editor1').addListener("ready", function () {});
</script>

<script type="text/javascript">
function uploadPic()
{
    $.ajaxFileUpload({
        url: '/api/face/uploadImage1', //用于文件上传的服务器端请求地址
        // url: '/api/face/ossUpload', //用于文件上传的服务器端请求地址
        secureuri: false, //是否需要安全协议，一般设置为false
        fileElementId: 'fileImage', //文件上传域的ID
        dataType: 'text/plain', //返回值类型 一般设置为json
        success: function (data, status) //服务器成功响应处理函数
        {
         if(data.err==0)
           {
               var img='<a href="'+data.data.pic+'" target="_blank"><img src="'+data.data.pic+'" style="width:120px;margin:5px;" />';
           $("#updateimg").html(img);
           $("#uImage").val(data.data.pic);
           }
       },
       error: function (data, status, e)//服务器响应失败处理函数
       {
        alert(e);
       }
    })
   return false;
}
function uploadPicV()
{
     $("#uploadProgress").html("<img  src='/static/admin/images/loading.gif' style='width:50px;' />");
     $.ajaxFileUpload(
       {
            url: '/api/face/uploadImage1', //用于文件上传的服务器端请求地址
            secureuri: false, //是否需要安全协议，一般设置为false
            fileElementId: 'fileVideo', //文件上传域的ID
            dataType: 'text/plain', //返回值类型 一般设置为json
            success: function (data, status) //服务器成功响应处理函数
            {

             if(data.err==0)
               {
                   var img='<a href="'+data.data.pic+'" target="_blank">'+data.data.pic+'</a>';
                    $("#updateimgV").html(img);
                    $("#uVideo").val(data.data.pic);
               }
            $("#uploadProgress").html("");
           },
           error: function (data, status, e)//服务器响应失败处理函数
           {
               $("#uploadProgress").html("异常");
           }
       })
    return false;
}
function myResearch(){
   var url="/admin/classlist/addData";
   var param={
   };
   ContentGet(url,param);
}
function runReward(days,task_time){
    if(!isNumber(days)){
        return false;
    }
    if(days>100 || days <=0) {
        return false;
    }
    if(task_time=="") {
        return false;
    }
    var url="/admin/classlist/runRewardDate";
    var param={
        days:days,
        task_time:task_time,
        sys_opt:'addData'//后台判断编辑操作
    };
    AjaxRequest(url,param,function(data){
        if(data.err==0) {
            $("#reward_date").val(data.data);
        } else
        {
            ErrTiShi(data.msg);
        }
    });
}
      
$(function(){
    var gnum=0;
    var lastObj;
    //设置搜索栏
    $(".research").click(function(){
       var page =$(this).attr("page");
       $("#cpage").val(page);
       myResearch();
    });
    $("#task_time").blur(function(){
        var task_time=$("#task_time").val();
        var days = $("#days").val();
        runReward(days,task_time);
    });
    $("#days").change(function(){
        var task_time=$("#task_time").val();
        var days = $("#days").val();
        runReward(days,task_time);
    });

    $(".add").unbind().bind("click",function(){

        var that =this;
        var url="/admin/classlist/addData";
        var generaData=$("[name^='data']");
        var classname=$("#classname").val();
        var bm_starttime=$("#bm_starttime").val();
        var bm_endtime=$("#bm_endtime").val();
        var task_time=$("#task_time").val();
        var reward_date=$("#reward_date").val();
        var conts=UE.getEditor('editor').getContent();
        var notice=UE.getEditor('editor1').getContent();
        if(classname=="") {
            ErrTiShi("挑战名称不能够为空");return false;
        }

        var days = $("#days").val();
        if(!isNumber(days)){
            ErrTiShi("挑战天数输入不正确");return false;
        }
        if(days>100 || days <=0) {
            ErrTiShi("挑战天数【1-100】的整数");return false;
        }

        var max = $("#max").val();
        if(!isNumber(max)){
            ErrTiShi("最大购买数量输入不正确");return false;
        }
        if(max>100 || max <=0) {
            ErrTiShi("最大购买数量输入不正确【1-100】的整数");return false;
        }

        var bm_starttime=$("#bm_starttime").val();
        var bm_endtime=$("#bm_endtime").val();
        var task_time=$("#task_time").val();

        if(bm_starttime=="") {
            ErrTiShi("请设置报名开始时间");return false;
        }
        if(bm_endtime=="") {
            ErrTiShi("请设置报名结束时间");return false;
        }
        if(task_time=="") {
            ErrTiShi("请设置任务开始时间");return false;
        }
        if(reward_date=="") {
            ErrTiShi("请设置开奖日期");return false;
        }
        if((new Date(bm_starttime)) > (new Date(bm_endtime)))
        {
            ErrTiShi("报名的开始时间不能早于报名结束时间");return false;
        }
        if((new Date(bm_endtime)) > (new Date(task_time)))
        {
            ErrTiShi("任务的开始时间不能早于报名结束时间");return false;
        }

        var param={
                data:{},
                conts:conts,
                notice:notice,
                sys_opt:'addData'//后台判断编辑操作
        };
        getFormData(generaData,param.data);
        AjaxRequest(url,param,function(data){
            if(data.err==0) {
                SuccessTiShi("操作成功");
                ContentLoadGo("/admin/classlist/lists");
            } else
            {
                ErrTiShi(data.msg);
            }
        });
    });

    //导航
    $(".topBannerItem").click(function(){
       var attArr = $(this).attr();
       goToSelfLink(attArr);
    });
});
</script>
{/block}